
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.Hashtable"%>
<%@page import="classes.Validate"%>

<link rel="stylesheet" href="css/login.css" type="text/css" />

<% 
request.setAttribute("page", "login");
String  cmd   = request.getParameter("cmd");
String  login = request.getParameter("uid");
String  pwd   = request.getParameter("pwd");
String  path  = config.getServletContext().getRealPath("/");
System.setProperty("dbPath", path);

int sid = 0;
String name = "";

if( cmd != null ) {
    Validate auth = new Validate();
    Hashtable user = auth.validateCredentials(login, pwd);
    Set set = user.keySet();
    Iterator iter = set.iterator();
    if( iter.hasNext() ) {
        sid = (Integer)iter.next();
        name = (String)user.get(sid);
    }
}

if( sid > 0 ) {
    session = request.getSession();
    session.setAttribute("validated", true);
    session.setAttribute("name", name);
    session.setMaxInactiveInterval(1800);
    response.sendRedirect("Profile.jsp?sid="+sid);
}
%>

<jsp:include page="header.jsp" flush="true"/>
<div class="home">
  <div class = "home-text">
    <p class="statement">
    Connect with classmates, friends, and teachers. Begin building your resume and apply to your favorite colleges online ! 
    </p>
    <img src="images/stickfigures.png"/>
  </div>
  <div class = "login-info">
    <form name="login" action="Login.jsp" method="post">
      <input type="hidden" name="cmd" value="validate">
        <div class="loginText" style="float:right; padding-right:50px;">
          Login <input type="text" id="uid" name="uid" size="15"/>
          Password <input type="password" name="pwd" size="15"/>
          <input type="submit" value="Sign In"/>
<%
  if( cmd != null && sid <= 0 ) {
%>
        <br><span class="error">Login and/or Password Incorrect.  Please try again.</span>
<%
  }
%>          
        </div>
    </form>
    <div style="text-align:left; margin-top:100px; margin-left:160px">
        <span class="loginBanner">Join SchooledIn Today !!</span>
    </div>
	<div class="cloud">
	  <img src="images/cloud.png">
	</div>
    <div class="login spacing">
      <form name="register" action="Register.jsp" method="Post">
        <div class="login">
          <span class="join">First Name</span>
          <input type="text" name="fname"/>
        </div>
        <div class="login">
          <span class="join">Last Name</span>
          <input type="text" name="lname"/>
        </div>
        <div class="login">
          <span class="join">Email</span>
          <input type="text" name="email"/>
        </div>
        <div class="login">
          <input type="submit" value="Register"/>
        </div>
        
      </form>
    </div>
  </div>
</div>

<jsp:include page="footer.jsp" flush="true"/>